package com.kaiyiweitong.tongxing.adapter;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;

import java.util.List;

/**
 * Created by Administrator on 2017/12/27 0027.
 */

public class HomeBannerAdapter extends PagerAdapter {
    private Context mContext;
    private List<View> mPics;

    public HomeBannerAdapter(Context context, List<View> pics) {
        mContext = context;
        mPics = pics;
    }

    @Override
    public int getCount() {
        if (mPics == null || mPics.size() == 0) {
            return 0;
        } else if (mPics.size() == 1) {
            return 1;
        } else {
            return Integer.MAX_VALUE;
        }
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        position = position % mPics.size();
        View view = mPics.get(position);
        ViewGroup parent = (ViewGroup) view.getParent();
        if (parent != null) {
            parent.removeView(view);
        }
        container.addView(view);
        return view;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }
}

